package services

import (
	"main_service/config"
	"main_service/models"
	"time"
)

type KlineService struct{}

func (s *KlineService) GetKlines(exchange, symbol string, interval string, startTime, endTime time.Time) ([]models.Kline, error) {
	var klines []models.Kline

	startTimeStr := startTime.Format("2006-01-02 15:04:05")
	endTimeStr := endTime.Format("2006-01-02 15:04:05")

	result := config.DB.Raw("SELECT * FROM dbbardata WHERE exchange = ? AND symbol = ? AND `interval` = ? AND datetime >= ? AND datetime <= ? ORDER BY datetime ASC",
		exchange, symbol, interval, startTimeStr, endTimeStr).Scan(&klines)

	if result.Error != nil {
		return nil, result.Error
	}

	return klines, nil
}
